import { HttpException, HttpStatus, Injectable } from '@nestjs/common';
import { JwtService } from '@nestjs/jwt';


export interface IJwtPayLoad {
    id: number;
    platform: string;
}

@Injectable()
export class AuthService {
  constructor(
    private readonly jwtService: JwtService,
  ) {}

  public generateToken(payload: object): string {
    return this.jwtService.sign({ ...payload})
  }

  public verifyToken(token: string): IJwtPayLoad{
    try {
      return this.jwtService.verify(token);
    } catch(e) {
      throw new HttpException('当前token无效', HttpStatus.OK);
    }
  }
}